package com.pignest.hotel.servlet.report;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import com.pignest.hotel.beans.TbCloseAccounts;
import com.pignest.hotel.beans.report.CheckoutDetail;
import com.pignest.hotel.service.ReportService;
import com.pignest.hotel.spring.Services;

public class CheckoutDetailReport extends BaseReport {
	
	@Override
	public void initParameters(HttpServletRequest req) {
		super.initParameters(req);
		notNull(startTime);
		if (endTime == null)
			endTime = new Date();
	}
	
	@Override
	public JRDataSource getDataSource(HttpServletRequest req) {
		ReportService service = Services.getReportService();
		List<TbCloseAccounts> accounts = service.reportCheckoutDetail(startTime, endTime);
		List<CheckoutDetail> details = new ArrayList<CheckoutDetail>();
		for (TbCloseAccounts tbCloseAccounts : accounts) {
			CheckoutDetail d = CheckoutDetail.fromCloseAccount(tbCloseAccounts);
			if (d != null)
				details.add(d);
		}
		return new JRBeanCollectionDataSource(details);
	}

	@Override
	public Map<String, Object> getParameters(HttpServletRequest req) {
		return null;
	}

	@Override
	public String getReportName() {
		return "结账明细表";
	}

}
